package com.guigu.youxuan.controller;

import com.guigu.youxuan.common.utils.PageUtils;
import com.guigu.youxuan.pojo.BackRole;
import com.guigu.youxuan.pojo.BackUser;
import com.guigu.youxuan.service.IBackRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@CrossOrigin
@RestController
@RequestMapping("/backRole")
public class BackRoleController {
    @Autowired
    private IBackRoleService backRoleService;

    @RequestMapping("/queryBackRoleList")
    public List<BackRole> queryBackRoleList() {
        List<BackRole> list = backRoleService.queryBackRoleList();
        return list;
    }

    /**
     * 角色列表分页
     * @param backRole
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping("/getBackRolePage/{currentPage}/{pageSize}")
    public PageUtils<BackRole> getBackRolePage(@RequestBody BackRole backRole,
                                               @PathVariable int currentPage,
                                               @PathVariable int pageSize) {
        PageUtils<BackRole> page =backRoleService.getBackRolePage(backRole,currentPage,pageSize);
        return page;
    }

    /**
     * 启用/禁用角色
     * @param backRole
     * @return
     */
    @RequestMapping("/switchStatus")
    public String switchStatus(@RequestBody BackRole backRole) {
        backRoleService.switchStatus(backRole);
        if (backRole.getStatus() == 0) {
            return "启用成功";
        }
        return "禁用成功";
    }

    /**
     * 添加角色
     * @param backRole
     * @return
     */
    @RequestMapping("/addRole")
    public String addRole(@RequestBody BackRole backRole) {
        backRoleService.addRole(backRole);
        return "新增角色成功";
    }
}
